﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Chaunce.FrameWork.NetCore.EasyRedis
{
    /// <summary>
    /// 满足常用redis操作的接口(压缩版)
    /// IRedisCache则是完整redis实现
    /// </summary>
    public interface ICacheManager
    {
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <typeparam name="T">Type of cached item</typeparam>
        /// <param name="key">Key of cached item</param>
        /// <returns>The cached value associated with the specified key</returns>
        T Get<T>(string key) where T : class;
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<T> GetAsync<T>(string key) where T : class;

        /// <summary>
        /// 新增缓存
        /// </summary>
        /// <param name="key">Key of cached item</param>
        /// <param name="data">Value for caching</param>
        /// <param name="cacheTime">Cache time in minutes</param>
        bool Set(string key, object data, int cacheTime);
        /// <summary>
        /// 新增缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="data"></param>
        /// <param name="cacheTime"></param>
        /// <returns></returns>
        Task<bool> SetAsync(string key, object data, int cacheTime);

        /// <summary>
        /// Gets a value indicating whether the value associated with the specified key is cached
        /// </summary>
        /// <param name="key">Key of cached item</param>
        /// <returns>True if item already is in cache; otherwise false</returns>
        bool IsSet(string key);

        /// <summary>
        /// 移除指定key的缓存
        /// </summary>
        /// <param name="key">Key of cached item</param>
        void Remove(string key);

        /// <summary>
        /// 删除缓存根据匹配key值
        /// </summary>
        /// <param name="pattern">String key pattern</param>
        void RemoveByPattern(string pattern);
        /// <summary>
        /// 删除缓存根据匹配key值
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        Task RemoveByPatternAsync(string pattern);

        /// <summary>
        /// 删除缓存根据 parentKey.parentKey规则一般取子keys的前面两部分,是自动的.
        /// </summary>
        /// <param name="key"></param>
        void RemoveByParentKey(string key);
    }
}
